<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>班组新增</title>
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/font/iconfont.css" media="all">
    <link rel="stylesheet" href="../js/formSelects/formSelects-v4.css">
    <style>
        .other_name {
            display: inline-block;
            margin-right: 10px;
            cursor: pointer;
        }
        .other_name>i {
            margin-left: 5px;
        }
        .other_name>i:hover {
            color: #FFFFFF;
        }

        .layui-form-label{
            width:140px;
        }
        .layui-input-block{
            margin-left: 170px;
        }
        a{
            color:#fff;
        }
        a:hover {
            color: #00c0ef;
        }
    </style>
</head>
<body>


<div style="margin-top: 40px; margin-right: 30px;">
    <form class="layui-form" action=""  lay-filter="dataForm" autocomplete=”off”>
        <div class="layui-form-item" id="companyDiv">
            <label class="layui-form-label"><span style="color:red">*</span>所属劳务公司</label>
            <div class="layui-input-block">
                <input type="text" name="companyName" id="companyName" style="background-color: #C0C0C0" readonly placeholder="所属劳务公司" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="projectDiv">
            <label class="layui-form-label"><span style="color:red">*</span>所属项目</label>
            <div class="layui-input-block">
                <select name="projectname"  id="projectname" lay-verify="required"   lay-search="">
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>工种</label>
            <div class="layui-input-block">
                <select name="profession"  id="profession" lay-verify="required"   lay-search="">
                </select>
            </div>
        </div>

        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">班组名称</label>-->
            <!--<div class="layui-input-block">-->
                <!--<input type="text" name="banzu_name" id="banzu_name"  lay-verify="required" readonly placeholder="班组名称" class="layui-input">-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">涉及人员</label>
            <div class="layui-input-block">
                <select name="number"  id="number" xm-select="number" lay-verify="required"   lay-search="">
                </select>
            </div>
        </div>

        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">人员数量</label>-->
            <!--<div class="layui-input-block">-->
                <!--<input type="text" name="number" id="number"  lay-verify="integer" placeholder="人员数量" class="layui-input">-->
            <!--</div>-->
        <!--</div>-->

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>班组负责人</label>
            <div class="layui-input-block">
                <input type="text" name="banzu_person"  id="banzu_person" lay-verify="required" placeholder="班组负责人" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>班组负责人电话</label>
            <div class="layui-input-block">
                <input type="text" name="banzu_person_phone"  id="banzu_person_phone"  lay-verify="required|phone" placeholder="班组负责人电话" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label"></label>
            <div class="layui-input-block" id="divOtherName">

            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button id="btnSub" class="layui-btn" lay-filter="formSubmit"  lay-submit="">提交</button>
            </div>
        </div>
    </form>
</div>

</body>
<script src="../assets/layui/layui.js"></script>
<script src="../js/common.js"></script>
<script>
    layui.config({
        base: '../js/'
    })
        .extend({
            formSelects: 'formSelects/formSelects-v4'
        });
    var $;
    layui.use(['jquery','form','validate','common','element', 'formSelects', 'laydate','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            validate = layui.validate,
            formSelects = layui.formSelects,
            common = layui.common;
        $ = layui.jquery;

        validate.regVerify();

        common.initSelectData("#projectname","../project/getSelectByProject?ddtype=project");
        common.initCommSelectData("#profession","../sys/dict/listMuti?ddtype=profession",true);
        formSelects.config("number",{
            keyName: 'name',
            keyVal: 'code'})
            .data("number","server",{
                url: '../project/getperson',
                success: function(id, url, searchVal, result){
                    formSelects.value('number',result);
                }
            });
        form.render('select');
        formSelects.render();

        $.ajax({
            url: "../project/pro_com_name",
            dataType: "json",
            success: function (rtn) {
                if(rtn!=null){
                    if(rtn.data==null){
                       $("#companyDiv").hide();
                    }
                    else {
                        form.val('dataForm', {
                            companyName: rtn.data
                        });
                        form.render();
                    }
                }
            }
        });
        form.on('submit(formSubmit)', function (data) {

            var profession = $("#profession").find("option:selected").val();
            var projectid = $("#projectname").find("option:selected").val();
            var banzu_person = $("#banzu_person").val();
            var banzu_person_phone = $("#banzu_person_phone").val();
            if(profession==""||projectid==""||banzu_person==""||banzu_person_phone=="")
            {
                common.showError('必填项不能为空!');
            }
//            var personname = formSelects.value('number', 'nameStr');
            var personid = formSelects.value('number', 'valStr');
//            var number = $("#number").val();
            var profession_name = $("#profession").find("option:selected").text();
            var projectname = $("#projectname").find("option:selected").text();

            data.field.number = personid;
            data.field.banzu_person = banzu_person;
            data.field.banzu_person_phone = banzu_person_phone;
            data.field.profession = profession;
            data.field.projectname = projectname;
            data.field.projectid = projectid;
            data.field.profession_name = profession_name;
            $.ajax({
                type: 'post',
                url: '../project/banzuadd',
                data: {json: JSON.stringify(data.field)},
                success: function (rtn) {
                    if (rtn.code === 0) {  //数据保存成功
                        var msg = "保存成功!";
                        common.showInfo(msg, function () {
                            //刷新前页
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.document.getElementById('btnSearch').click();
                            parent.layer.close(index);
                        });
                    }
                    else {
                        common.showError(rtn.msg);
                    }
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    common.showError('保存错误');
                }
            });
            return false;
        });


        //按钮事件绑定
        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>
</html>